class ContactsController < ApplicationController
  
  def new 
  end

  def create 
    @contact = Contact.new
    @contact.message = params['message'] 
    @contact.subject = params['subject']
    @contact.name = sender
    
    begin
      @contact.save
      ContactMailer::deliver_contact_message(@contact) 
      flash[:notice] = "Your message has been sent!" 
      redirect_to root_url
    rescue  
      flash[:notice] = "Message delivery failed." 
      redirect_to root_url
    end
  end

  private

  def sender
    u = User.find(current_user.id)
    u.first_name + ' ' + u.last_name
  end
end